package com.carleasoft.mps.cms.business.resource.controller;

import com.carleasoft.mps.cms.business.resource.bean.entity.LibraryEntity;
import com.carleasoft.mps.cms.business.resource.bean.vo.LibraryTreeVo;
import com.carleasoft.mps.cms.business.resource.service.LibraryService;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.utils.IBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 资源库
 *
 * @author: yangHao
 * @createDate:2023/6/6
 * @description:
 */
@RestController
@RequestMapping("/library")
public class LibraryController {

    @Autowired
    private LibraryService libraryService;

    /**
     * 添加/编辑 所属库
     *
     * @param libraryEntity
     * @return
     */
    @PostMapping("/save")
    public R save(@RequestBody LibraryEntity libraryEntity) {
        boolean isOk = libraryService.saveLibrary(libraryEntity);
        return R.ok(isOk);
    }

    /**
     * 查询所属库集合
     *
     * @param
     * @return
     */
    @PostMapping("/select")
    public R select() {
        List<LibraryEntity> libraryEntities = libraryService.select();
        return R.ok(libraryEntities);
    }

    /**
     * 删除
     *
     * @param libraryEntity
     * @return
     */
    @PostMapping("/delete")
    public R delete(@RequestBody LibraryEntity libraryEntity) {
        IBeanUtil.paramVerify(libraryEntity, "libraryCode");
        boolean isOk = libraryService.delete(libraryEntity);
        return R.ok(isOk);
    }


    /**
     * 查询资源库树
     * @return
     */
    @PostMapping("/getTree")
    public R getTree() {
        List<LibraryTreeVo> libraryTreeVos = libraryService.getTree();
        return R.ok(libraryTreeVos);
    }

}
